package dao.Impl;

import dao.StudentDao;
import org.apache.commons.dbutils.DbUtils;
import po.Course;
import po.Student;
import util.DBUtils;
import util.DaoRepeat;

import java.sql.SQLException;
import java.util.List;
import java.util.Map;

public class StudentDaoImpl extends BaseDaoImpl<Student> implements StudentDao {


    @Override
    public Student queryStudentByNameAndPassword(String username, String password) {
        Student student= queryOne("select * from Student where username=? and password=?", Student.class, username, password);
        return student;
    }





    @Override
    public List<Student> queryAllStudent(Integer id) {
        List<Student> students = queryMany("select * from Student where classId=?", Student.class, id);
        return students;
    }

    @Override
    public boolean addStudent(Student student) {
        try {
            insert(student,DBUtils.getConnection());
        } catch (SQLException e) {
            e.printStackTrace();
        }return  true;
    }

    @Override
    public boolean deleteStudent(Student student) {
        try {
            delete(student,DBUtils.getConnection());
        } catch (SQLException e) {
            e.printStackTrace();
        }return  true;
    }

    @Override
    public boolean updateStudent(Student student) {
        try {
            update(student,DBUtils.getConnection());
        } catch (SQLException e) {
            e.printStackTrace();
        }return  true;
    }

    @Override
    public Student queryOneStudent(Integer id) {
        Student student = queryOne("select * from Student where id=?", Student.class, id);
        return  student;
    }
}